/**
* Created by ren on 2017/1/3.
*/
<template>
  <div class='inputPwd shade-background'>
    <div class="inputpwd">
      <div class="quit" style="position: absolute;right: 21px;top: 0;font-size: 40px;color: #bfbfbf;cursor: pointer;"
           @click="close">x
      </div>
      <div class="t1">
        <img src="../assets/true5.png" alt=""><span>您在安全的环境当中，请放心使用！</span>
      </div>
      <div class="t2">请输入支付密码</div>
      <div class="inputgroup">
        <input type="password" v-model="text1" id="text1">
        <input type="password" v-model="text2" id="text2">
        <input type="password" v-model="text3" id="text3">
        <input type="password" v-model="text4" id="text4">
        <input type="password" v-model="text5" id="text5">
        <input type="password" class="end" v-model="text6" id="text6">
      </div>
      <div class="t3">请输入6位数字支付密码</div>
      <button class="btn" @click="pay">确定</button>
    </div>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../api'
  import Notify from '../components/Notify'
  import md5 from 'blueimp-md5'
  export default {
    name: 'inputPwd',
    components: {
      Notify
    },
    data: function () {
      return {
        text1: null,
        text2: null,
        text3: null,
        text4: null,
        text5: null,
        text6: null,
        notifyStatus: 2
      }
    },
    props: ['_parentThis'],
    methods: {
      close: function () {
        this._parentThis.inputPwdStatus = false
        this._parentThis.butText = '确定支付'
      },
      pay: function () {
        if (this.$cookie.get('existPay') === 0) {
        } else {
          var param = []
          switch (this._parentThis.style) {
            case 'sp':
              param = {
                orderNo: this._parentThis.orderObject.orderNo,
                userId: this.$cookie.get('id'),
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isRenew: 0
              }
              this.$http.post(API.accountPay, param).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$cookie.set('redpack_orderNo', this._parentThis.orderObject.orderNo)
                  this.$router.push({'name': 'paySuccess'})
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text1 = this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this._parentThis.butText = '确定支付'
              })
              break
            case 'dttq':
              param = {
                orderNo: this._parentThis.orderObject.orderNo,
                userId: this.$cookie.get('id'),
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isRenew: 1
              }
              this.$http.post(API.accountPay, param).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$cookie.set('redpack_orderNo', '')
                  this.$router.push({
                    name: 'paySuccess'
                  })
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = this.text1 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this._parentThis.butText = '确定支付'
              })
              break
            case 'dt':
              param = {
                orderId: this._parentThis.dingtuoData.id,
                userId: this.$cookie.get('id'),
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isRenew: 0
              }
              this.$http.post(API.accountPay, param).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$cookie.set('redpack_orderNo', this._parentThis.dingtuoData.orderNo)
                  this.$router.push({'name': 'paySuccess'})
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text1 = this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this._parentThis.butText = '确定支付'
              })
              break
            case 'jsj':
              this.$http.post(API.kinsonSaveOrder, {
                userId: this.$cookie.get('id'),
                orderNumber: 1,
                weight: this._parentThis.orderObject.weight,
                kinsonGoldId: this._parentThis.orderObject.kinsonGoldId,
                payType: 2,
                useRange: 1,
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isUseGoldBean: this._parentThis.isUseGold ? 1 : 0,
                qishu: 1
              }).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$router.push({'name': 'paySuccess'})
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text1 = this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this.butText = '确定支付'
              })
              break
            case 'jsjtq':
              param = {
                orderNo: this._parentThis.orderObject.orderNo,
                userId: this.$cookie.get('id'),
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isRenew: 1
              }
              this.$http.post(API.accountPay, param).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$cookie.set('redpack_orderNo', '')
                  this.$router.push({
                    name: 'paySuccess'
                  })
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text1 = this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this._parentThis.butText = '确定支付'
              })
              break
            case 'moreGoods':
              param = {
                orderNo: this._parentThis.orderObject.orderNo,
                userId: this.$cookie.get('id'),
                payPassword: md5('Au+' + ((this.text1 + this.text2 + this.text3 + this.text4 + this.text5 + this.text6) * 103)),
                isRenew: 0
              }
              this.$http.post(API.accountPay, param).then((ret) => {
                const result = ret.body
                if (result.code === 1) {
                  this.$router.push({'name': 'paySuccess'})
                } else {
                  this.notifyStatus = '0|' + result.message
                  this.text1 = this.text2 = this.text3 = this.text4 = this.text5 = this.text6 = ''
                }
                this._parentThis.butText = '确定支付'
              }, (err) => {
                console.log(err)
                this._parentThis.butText = '确定支付'
              })
              break
          }
        }
      }
    },
    watch: {
      text1: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {
              document.getElementById('text2').focus()
            } else {
              this.text1 = oldVal
            }
          } else {
            this.text1 = oldVal
          }
        } else {
          document.getElementById('text1').focus()
        }
      },
      text2: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {
              document.getElementById('text3').focus()
            } else {
              this.text2 = oldVal
            }
          } else {
            this.text2 = oldVal
          }
        } else if (this.text1) {
          document.getElementById('text1').focus()
        }
      },
      text3: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {
              document.getElementById('text4').focus()
            } else {
              this.text3 = oldVal
            }
          } else {
            this.text3 = oldVal
          }
        } else if (this.text2) {
          document.getElementById('text2').focus()
        }
      },
      text4: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {
              document.getElementById('text5').focus()
            } else {
              this.text4 = oldVal
            }
          } else {
            this.text4 = oldVal
          }
        } else if (this.text3) {
          document.getElementById('text3').focus()
        }
      },
      text5: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {
              document.getElementById('text6').focus()
            } else {
              this.text5 = oldVal
            }
          } else {
            this.text5 = oldVal
          }
        } else if (this.text4) {
          document.getElementById('text4').focus()
        }
      },
      text6: function (newVal, oldVal) {
        if (newVal) {
          if (/^(0|[1-9]\d*)$/.test(newVal)) {
            if (newVal.length === 1) {

            } else {
              this.text6 = oldVal
            }
          } else {
            this.text6 = oldVal
          }
        } else if (this.text5) {
          document.getElementById('text5').focus()
        }
      }
    }
  }
</script>

<style>
  .inputPwd {
  }
</style>
